package com.example.dataservice.serviceimpl;

import com.example.dataservice.mapper.BidInfoMapper;
import com.example.dataservice.mapper.ProductInfoMapper;
import com.example.dataservice.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboService;
import org.example.api.model.User;
import org.example.api.pojo.BaseInfo;
import org.example.api.service.PlatBaseInfoService;

import java.math.BigDecimal;
import java.util.List;

/**
 * @description: TODO
 * @author: uu
 * @data: 2023/7/11 下午 06:34
 * @version: v1.0
 */
@DubboService(interfaceClass = PlatBaseInfoService.class, version = "1.0")
public class PlatBaseInfoServiceImpl implements PlatBaseInfoService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private ProductInfoMapper productInfoMapper;
    @Resource
    private BidInfoMapper bidInfoMapper;

    /*平台基本信息*/
    @Override
    public BaseInfo queryPlatBaseInfo() {
        /*注册人数，收益平均值，累计成交金额*/
        int registerUser = userMapper.selectCountUser();
        /*收益平均值*/
        BigDecimal avgRate = productInfoMapper.selectAvgRate();
        /*累计成交额*/
        BigDecimal subBidMoney = bidInfoMapper.selectSumBidMoney();
        BaseInfo baseInfo = new BaseInfo(avgRate,subBidMoney,registerUser);

        return baseInfo;
    }

    @Override
    public List<User> queryAllUserInfo() {
        List<User> users = userMapper.selectAllUser();
        return users;
    }

}
